<template>
	<view class="public-nearby-content">
		<view
			class="position"
			@click="clickChooseLocation">
			<view class="map-button">
				<text class="iconfont icon-map"></text>
				<text>{{detailedLocation?'重新获取':'获取位置'}}</text>
			</view>
		</view>
		<view class="map-text" v-if="detailedLocation">
			<text class="iconfont icon-map"></text>
			<text>{{detailedLocation.address}}</text>
		</view>
		<template v-if="detailedLocation">
			<view class="list-interact" v-if="listPostState == 'success'">
				<view
					@click="$_To('post/post?pid='+item.pid)"
					class="for Flex"
					v-for="item in listPost">
					<view
						class="left"
						@click.stop="$_To('user/user?uid=' + item.author.uid)">
						<image :src="item.author.avatar" mode="widthFix"></image>
					</view>
					<view class="right">
						<view class="nickname Zt-ShenLanSe">{{item.author.nickname?item.author.nickname:'?'}}
							<text class="P" :style="item.author.nicknameColor?'color:'+item.author.nicknameColor+';':''">{{item.author.roleName}}</text>
						</view>
						<!-- 文字摘要 -->
						<view class="title" v-if="item.title">{{item.title}}</view>
						<view class="content">{{$_filterHtml(item.content)}}</view>
						<!-- 图片 -->
						<view class="image Flex" v-if="item.files.images.length">
							<view
								@click.stop="$_picturePreview(index,item.files.images)"
								v-for="(images,index) in item.files.images">
								<image :src="images.imageRatioUrl" mode="widthFix"></image>
							</view>
						</view>
						<!-- 视频列表 -->
						<view class="video" v-if="!item.files.images.length && item.files.videos.length">
							<view class="image-cover">
								<image :src="item.files.videos[0].videoPosterUrl" mode="widthFix"></image>
							</view>
							<text class="Flex iconfont icon-play"></text>
						</view>
						<view class="group" v-if="item.group || item.hashtags">
							<view class="_group" v-if="item.group">
								<view><image :src="item.group.cover" mode="widthFix"></image></view>
								<text>{{item.group.gname}}</text>
							</view>
							<view class="_hashtag" v-if="item.hashtags">#{{item.hashtags[0].hname}}#</view>
						</view>
						<view
							class="post-info Flex"
							:style="!item.previewLikeUsers && !item.previewComments?'margin-bottom: 0;':''">
							<view class="_position" v-if="item.location && item.location.poi">
								<text class="iconfont icon-dingwei1"></text>
								<text class="_position_POI">{{item.location.poi}}</text>
							</view>
							<text class="P">{{item.createdTimeAgo}}</text>
							<view class="type Flex">
								<text class="Bj-LanSe iconfont icon-tupian" v-if="item.files.images.length"></text>
								<text class="Bj-HongSe iconfont icon-zhibo" v-if="item.files.videos.length"></text>
								<text class="Bj-LvSe iconfont icon-yuyin" v-if="item.files.audios.length"></text>
								<text class="Bj-BianKuangSe iconfont icon-gengduo"></text>
							</view>
						</view>
						<view class="like Bj-BeiJingSe" v-if="item.previewLikeUsers">
							<text class="iconfont icon-dianzan"></text>
							<template v-for="item_DianZan in item.previewLikeUsers">
								<text class="H3">{{item_DianZan.nickname}},</text>
							</template>
						</view>
						<view class="comment Bj-BeiJingSe" v-if="item.previewComments">
							<template v-for="item_PingLun in item.previewComments">
								<view class="_for">
									<text class="_nickname Zt-ShenLanSe">{{item_PingLun.author.nickname}}:</text>
									<text class="iconfont icon-yuyin" v-if="item_PingLun.files.audios.length"></text>
									<text>{{$_filterHtml(item_PingLun.content)}}</text>
								</view>
							</template>
						</view>
					</view>
				</view>
				<view
					@click="getPostList('more')"
					class="more">点击加载更多</view>
			</view>
			<template v-if="listPostState == 'loading'">
				<view class="skeleton-screen">
					<view class="left loading-css"></view>
					<view class="right">
						<view class="loading-css"></view>
						<view class="loading-css"></view>
						<view class="loading-css"></view>
					</view>
				</view>
				<view class="skeleton-screen">
					<view class="left loading-css"></view>
					<view class="right">
						<view class="loading-css"></view>
						<view class="loading-css"></view>
						<view class="loading-css"></view>
					</view>
				</view>
				<view class="skeleton-screen">
					<view class="left loading-css"></view>
					<view class="right">
						<view class="loading-css"></view>
						<view class="loading-css"></view>
						<view class="loading-css"></view>
					</view>
				</view>
			</template>
			<public-empty v-if="listPostState == 'empty'"></public-empty>
		</template>
	</view>
</template>

<script>
	export default {
		name:"public-nearby-content",
		data() {
			return {
				detailedLocation:null,
				listPost:[],
				listPostState:"loading",
				listPostPage:2,
			};
		},
		mounted(){
			
		},
		methods:{
			// 选择位置
			clickChooseLocation(){
				uni.chooseLocation({
					success: (res) => {
						this.detailedLocation = res;
						this.getPostList();
					}
				});
			},
			// 获取帖子列表
			getPostList(more){
				if(more == 'more'){uni.showLoading({ title: "加载中" });}
				this.$_Request(
					"GET","/api/v2/post/nearby",
					{
						"mapId":4,
						"mapLng":this.detailedLocation.longitude,
						"mapLat":this.detailedLocation.latitude,
						"page":more == 'more' ? this.listPostPage : "",
						"whitelistKeys":"pid,createdTimeAgo,author.nickname,author.nicknameColor,author.roleName,title,content,author.avatar,author.uid,files,group.cover,group.gname,hashtags.0.hname,location,previewLikeUsers.0.nickname,previewLikeUsers.1.nickname,previewLikeUsers.2.nickname,previewLikeUsers.3.nickname,previewLikeUsers.4.nickname,previewLikeUsers.5.nickname,previewLikeUsers.6.nickname,previewLikeUsers.7.nickname,previewLikeUsers.8.nickname,previewLikeUsers.9.nickname,previewComments.0.author.nickname,previewComments.0.files.audios,previewComments.0.content,previewComments.1.author.nickname,previewComments.1.files.audios,previewComments.1.content,previewComments.2.author.nickname,previewComments.2.files.audios,previewComments.2.content,previewComments.3.author.nickname,previewComments.3.files.audios,previewComments.3.content,previewComments.4.author.nickname,previewComments.4.files.audios,previewComments.4.content,previewComments.5.author.nickname,previewComments.5.files.audios,previewComments.5.content"
					},
					(res) => {
						if(more == 'more'){
							if(res.data.data.list.length){
								this.listPost = this.listPost.concat(res.data.data.list);
								this.listPostPage++
								uni.hideLoading();
							}else{
								uni.showToast({
									title: "没有数据啦",
									icon: "none",
									duration: 1000
								});
							}
						}else{
							if(res.data.data.list.length){
								this.listPost = res.data.data.list;
								this.listPostState = "success"
							}else{
								this.listPostState = "empty"
							}
						}
					}
				)
			},
		},
	}
</script>

<style lang="scss" scoped>
.public-nearby-content{
	.position{
		margin: 25rpx 25rpx 0 25rpx;
		background: $BeiJingSe;
		border: 1rpx solid $BianKuangSe;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 25rpx;
		border-radius: 100rpx;
		.map-button{
			display: flex;
			align-items: center;
			justify-content: center;
			text{
				font-size: 28rpx;
				line-height: 28rpx;
			}
			.icon-map{
				font-size: 40rpx;
				line-height: 40rpx;
				padding-right: 10rpx;
			}
		}
	}
	.map-text{
		margin: 25rpx 25rpx 0 25rpx;
		display: flex;
		align-items: center;
		display: -webkit-box;
		/*!autoprefixer:off*/
		-webkit-box-orient: vertical;
		/*autoprefixer:on*/
		-webkit-line-clamp: 1;
		overflow: hidden;
		text{
			font-size: 28rpx;
			line-height: 35rpx;
			flex-shrink: 0;
		}
		.icon-map{
			font-size: 40rpx;
			line-height: 40rpx;
			padding-right: 5rpx;
		}
	}
	.list-interact{
		padding: 0 25rpx;
		.for{
			padding: 25rpx 0;
			border-bottom: 1rpx solid $BeiJingSe;
			.left{
				width: 80rpx;
				height: 80rpx;
				overflow: hidden;
				border-radius: 15rpx;
				flex-shrink: 0;
			}
			.right{
				flex: 1;
				margin-left: 25rpx;
				.nickname{
					font-weight: bold;
					.P{
						font-weight: normal;
						padding-left: 15rpx;
					}
				}
				.title{
					font-weight: bold;
					margin-top: 5rpx;
					display: -webkit-box;
					/*!autoprefixer:off*/
					-webkit-box-orient: vertical;
					/*autoprefixer:on*/
					-webkit-line-clamp: 1;
					overflow: hidden;
				}
				.content{
					word-break: break-all;
					margin-top: 5rpx;
					display: -webkit-box;
					/*!autoprefixer:off*/
					-webkit-box-orient: vertical;
					/*autoprefixer:on*/
					-webkit-line-clamp: 3;
					overflow: hidden;
				}
				.image{
					flex-wrap: wrap;
					margin-top: 10rpx;
					view{
						width: 194rpx;
						height: 150rpx;
						overflow: hidden;
						box-shadow: 0 0 1rpx $ZhanWeiSe;
						margin-top: 10rpx;
					}
					view:nth-child(2),view:nth-child(5),view:nth-child(8){
						margin: 10rpx 10rpx 0 10rpx;
					}
					// #ifdef MP-WEIXIN
					view{
						margin-top: 8rpx;
					}
					view:nth-child(2),view:nth-child(5),view:nth-child(8){
						margin: 8rpx 8rpx 0 8rpx;
					}
					// #endif
				}
				.video{
					margin-top: 20rpx;
					width: 100%;
					height: 300rpx;
					overflow: hidden;
					border-radius: 10rpx;
					position: relative;
					.image-cover{
						position: absolute;
						top: 0;
						left: 0;
						z-index: 1;
						width: 100%;
						height: 300rpx;
						overflow: hidden;
					}
					.icon-play{
						position: absolute;
						top: 0;
						left: 0;
						z-index: 2;
						width: 100%;
						height: 300rpx;
						align-items: center;
						justify-content: center;
						color: #FFF;
						text-shadow: 0 0 1rpx #000;
						font-size: 100rpx;
						line-height: 100rpx;
						background-color:rgba(0,0,0,0.5);
					}
				}
				.group{
					display: flex;
					align-items: center;
					margin-top: 25rpx;
					._group{
						display: flex;
						align-items: center;
						background: $BeiJingSe;
						border-radius: 100rpx;
						margin-right: 20rpx;
						view{
							width: 45rpx;
							height: 45rpx;
							overflow: hidden;
							border-radius: 100%;
						}
						text{
							font-size: 22rpx;
							line-height: 22rpx;
							padding: 0 20rpx 0 15rpx;
						}
					}
					._hashtag{
						display: flex;
						align-items: center;
						border-radius: 100rpx;
						height: 45rpx;
						background: $BeiJingSe;
						font-size: 22rpx;
						line-height: 22rpx;
						padding: 0 15rpx;
						margin-right: 20rpx;
					}
				}
				.post-info{
					margin: 25rpx 0;
					align-items: center;
					._position{
						display: flex;
						align-items: center;
						line-height: 22rpx;
						margin-right: 10rpx;
						text{
							font-size: 22rpx;
							line-height: 22rpx;
							color: $ZhanWeiSe;
						}
						.iconfont{
							margin-right: 5rpx;
						}
						._position_POI{
							max-width: 350rpx;
							display: -webkit-box;
							/*!autoprefixer:off*/
							-webkit-box-orient: vertical;
							/*autoprefixer:on*/
							-webkit-line-clamp: 1;
							overflow: hidden;
						}
					}
					.type{
						flex: 1;
						align-items: center;
						justify-content: flex-end;
						text{
							margin-left: 10rpx;
							color: #FFF;
							font-size: 18rpx;
							line-height: 18rpx;
							padding: 5rpx;
							border-radius: 2rpx;
						}
						.icon-gengduo{
							display: flex;
							align-items: center;
							justify-content: center;
							color: $YuanSe;
							padding: 0 10rpx;
							height: 26rpx;
						}
					}
				}
				.like{
					padding: 15rpx 20rpx;
					line-height: 38rpx;
					border-bottom: 1px solid $BianKuangSe;
					text{
						color: $ShenLanSe;
					}
					.icon-dianzan{
						font-size: 32rpx;
						padding: 0 5rpx 0 0;
						position: relative;
						top: .5rpx;
					}
					.H3{
						line-height: 38rpx;
						margin-right: 10rpx;
					}
				}
				.comment{
					padding: 10rpx 0 15rpx 0;
					border-radius: 10rpx;
					._for{
						padding: 5rpx 25rpx 0 25rpx;
						line-height: 40rpx;
						text{
							font-size: 28rpx;
						}
						._nickname{
							flex-shrink: 0;
							padding-right: 10rpx;
						}
						.icon-yuyin{
							font-size: 22rpx;
							line-height: 22rpx;
							padding-right: 5rpx;
							color: $LvSe;
						}
					}
				}
			}
		}
		.more{
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			line-height: 28rpx;
			color: $ZhanWeiSe;
			padding: 35rpx 0;
		}
	}
}
.skeleton-screen{
	display: flex;
	border-bottom: 1rpx solid $BeiJingSe;
	padding: 25rpx;
	.left{
		width: 80rpx;
		height: 80rpx;
		overflow: hidden;
		border-radius: 15rpx;
		flex-shrink: 0;
	}
	.right{
		flex: 1;
		margin-left: 25rpx;
		view:nth-child(1){
			width: 100%;
			height: 40rpx;
		}
		view:nth-child(2){
			width: 100%;
			height: 120rpx;
			margin: 15rpx 0;
		}
		view:nth-child(3){
			width: 100%;
			height: 150rpx;
		}
	}
}
</style>